<?php
namespace Common\Model;
use Common\Model\BaseModel;
class ReportModel extends BaseModel
{
    protected $tableName = 'report';

    public function addReport($post)
    {

    	$ret = array('status'=>'','info'=>'');
    	$data = $this->returnData($post);
    	if($this->create($data))
        {
    		$res = null !== $data['report_id'] ? $this->save($data) : $this->add($data);
    		if(false !== $res)
            {
    			$ret['status'] = true;
    			$ret['info']   = "Success";
    		}
            else
            {
    			$ret['status'] = false;
    			$ret['info']   = $this->getDbError();
    		}
    	}
        else
        {
    			$ret['status'] = false;
    			$ret['info']   = $this->getError();
    	}
    
    	return $ret;
    }
    public function returnData($post)
    {
    	$return['report_id'] 		= !empty($post['report_id']) ? intval($post['report_id']) : null;
    	$return['staff_id'] 	    = $this->staff_id;
    	$return['informant'] 		= !empty($post['informant']) ? addslashes($post['informant']) : '';
    	$return['id_card'] 			= !empty($post['id_card']) ? addslashes($post['id_card']) : '';
    	$return['phone'] 			= !empty($post['phone']) ? addslashes($post['phone']) : '';
    	$return['unit'] 		    = !empty($post['unit']) ? addslashes($post['unit']) : '';
    	$return['address'] 		    = !empty($post['address']) ? addslashes($post['address']) : '';
    	$return['happen_place'] 	= !empty($post['happen_place']) ? addslashes($post['happen_place']) : '';
    	$return['report_time'] 		= !empty($post['report_time']) ? strtotime($post['report_time']) : time();
		$return['happen_stime']     = !empty($post['happen_stime']) ? strtotime($post['happen_stime']) : time();
		$return['happen_etime']     = !empty($post['happen_etime']) ? strtotime($post['happen_etime']) : time();
		$return['happen_content']   = !empty($post['happen_content']) ? addslashes($post['happen_content']) : '';
		$return['status'] 			= !empty($post['status']) ? intval($post['status']) : 1;
		$return['extern'] 			= !empty($post['extern']) ? addslashes($post['extern']) : '';
		$return['reg_time']			= !empty($post['reg_time']) ? strtotime($post['reg_time']) : time();
		$return['del'] 				= 1;
 		
 		return $return;  
    }

}